/*
 * Project CHEN Rendering Engine : /diffuse.hpp
 * Created: 2021-03-01, Last modified:  2021-03-01
 * 
 * This is the most naive material you can think of.
 * 
 * Copyright (C) 2021 Hineven (hineven@pku.edu.cn)
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#ifndef _H_MATERIAL_DIFFUSE
#define _H_MATERIAL_DIFFUSE
#include "../core/material.hpp"
#include "../core/texture.hpp"
#include "../core/buffer.hpp"
#include "../core/bsdf.hpp"
namespace chen {

class DiffuseMaterial : public Material {
    const Texture<Spectrum> * albedo;
public:
    inline DiffuseMaterial (
        const Texture<Normal> * bumpmap, const Texture<Spectrum> * albedo
    ):
        Material::Material(bumpmap), albedo(albedo) {}
    inline bool apply (SurfInteract * si, bool dir) const {
        bump(si); // calculate shaing variables
        Spectrum sc = albedo->sample(*si);
        BSDF * bsdf = balloc(BSDF)(si->ng, si->ns, si->nsy, 1);
        bsdf->append(balloc(DiffuseBxDF)(sc));
        si->bsdf = bsdf;
        si->bssrdf = nullptr;
        return true;
    }
};


}
#endif